#ifndef __BUS_FIFO_H
#define __BUS_FIFO_H

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

#include "data.h"

char *strdup(const char *s);

typedef struct
{
	char *path;
	int fd;
} z_fifo;

z_fifo z_fifo_init(char *p);
int z_fifo_release(z_fifo f);
char *z_fifo_path_get(z_fifo *f);
char *z_fifo_path_set(z_fifo *f, char *p);
int z_fifo_filedesc_get(z_fifo *f);

int z_fifo_is_created(z_fifo *f);
int z_fifo_create(z_fifo *f);
int z_fifo_connect_read(z_fifo *f);
int z_fifo_connect_write(z_fifo *f);
int z_fifo_disconnect(z_fifo *f);

void *z_fifo_read(z_fifo *f, z_size s);
int z_fifo_write(z_fifo *f, z_size s, void *d);

#define Z_FIFO_PARENT_TO_CHILD 0
#define Z_FIFO_CHILD_TO_PARENT 1

typedef struct
{
	int me;
	z_fifo f[2];
} z_ipc;

z_ipc z_ipc_init(char *basedir, int id, int me);
int z_ipc_release(z_ipc i);
int z_ipc_me_get(z_ipc *i);
int z_ipc_me_set(z_ipc *i, int m);
z_fifo z_ipc_fifo_me(z_ipc *i);
z_fifo z_ipc_fifo_them(z_ipc *i);
z_data z_ipc_request_data(z_ipc *i, z_data d);
z_data z_ipc_wait_on_request(z_ipc *i);
int z_ipc_send_data(z_ipc *i, z_data d);

#endif
